/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.iti.jets.gpts.beans;
import com.iti.jets.gpts.service.Authentication;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

/**
 *
 * @author noha
 */
@ManagedBean(name = "login")
@ViewScoped
public class loginbean implements Serializable
{
  String username;
  String password;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    
    public String checklogin()
    {
        System.out.println("da5al al check loginnnnnnnnnnnnnnnn");
      Authentication loginservice=new Authentication();
      String user=loginservice.login(username, password);
      try {
          JSONObject userjson = new JSONObject(user.toString());
          boolean admin=userjson.getBoolean("isAdmin");
          if(admin==true)
          {
              return "index";
          }
          else{return "login";}
      } catch (JSONException ex) {
         ex.printStackTrace();
      }
      
      return"";
    }
  
}
